class Event {
    constructor() {
        this._events = [];
    }
    on(fn) {
        this._events.push(fn);
    }
    emit(data) {
        this._events.forEach(fn => fn(data));
    }
}

let event = new Event();
event.on(() => {
    console.log('xxx');
})
event.on(() => {
    console.log('yyy');
})

event.emit();
